import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createPinia } from 'pinia'
import { useUserInfoStore } from './pinia/userinfo'
import { reactive } from 'vue';

const app = createApp(App)
const baseUrl = reactive({
    SPRURL: "http://127.0.0.1:9999/"
});
app.use(createPinia())
app.config.globalProperties.$baseUrl = baseUrl;

app.use(router)
app.use(ElementPlus)

// 获取 Pinia store 实例
const userInfoStore = useUserInfoStore()
// 检查 localStorage 中是否存在用户名和 token
const storedUname = localStorage.getItem("uname")
const storedToken = localStorage.getItem("token")
if (storedUname && storedToken) {
  // 如果存在，则将其设置到 Pinia store 中
  userInfoStore.setUserInfo(storedUname, storedToken)
}

app.mount('#app')